<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" size="small" v-has="'Apk:add'">新增</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">

        <template slot="isNewest" slot-scope="text, record, index">
          <a-tag v-if="record.isNewest=='0'" color="green">{{record.isNewest_dictText}}</a-tag>
          <a-tag v-if="record.isNewest=='1'" color="red">{{record.isNewest_dictText}}</a-tag>
        </template>

        <span slot="remark" slot-scope="text">
          <j-ellipsis :value="text" :length="50"/>
        </span>

        <template slot="address" slot-scope="text">
          <a-tag color="orange" v-if="!text">当前无地址</a-tag>
          <a v-else @click="handleDownload(text)">{{text}}</a>
        </template>

        <template slot="yuliu" slot-scope="text">
          <a-tag color="orange" v-if="!text">当前无文件</a-tag>
          <a v-else @click="handleDownloadYL(text)">{{text}}</a>
        </template>

        <span slot="action" slot-scope="text, record" class="publicFlex">
          <a @click="handleEdit(record)"  v-has="'Apk:edit'">编辑</a>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)" v-has="'Apk:delete'">
                  <a>删除</a>
                </a-popconfirm>
        </span>
      </a-table>
    </div>

    <soApk-modal ref="modalForm" @ok="modalFormOk"></soApk-modal>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import SoApkModal from './modules/SoApkModal'
  import JEllipsis from '@/components/jeecg/JEllipsis';

  export default {
    name: 'SoApkList',
    mixins: [JeecgListMixin],
    components: {
      JEllipsis,
      SoApkModal
    },
    data() {
      return {
        description: 'apk版本升级管理页面',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function(t, r, index) {
              return parseInt(index) + 1
            }
          },
          {
            title: 'apk版本',
            align: 'center',
            dataIndex: 'apkVersion'
          },
          {
            title: '是否是最新版本',
            align: 'center',
            dataIndex: 'isNewest',
            scopedSlots: { customRender: 'isNewest' }
          },
          /*{
            title: '下载地址',
            align: 'center',
            dataIndex: 'address',
            scopedSlots: { customRender: 'address' }
          },*/
          {
            title: '文件',
            align: 'center',
            dataIndex: 'yuliu',
            scopedSlots: { customRender: 'yuliu' }
          },
          {
            title: '备注',
            align: 'center',
            dataIndex: 'remark',
            scopedSlots: { customRender: 'remark' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: '/apk/sysApk/list',
          delete: '/apk/sysApk/delete',
          deleteBatch: '/apk/sysApk/deleteBatch',
          exportXlsUrl: '/apk/sysApk/exportXls',
          importExcelUrl: 'apk/sysApk/importExcel'
        }
      }
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      }
    },
    methods: {
      initDictConfig() {
      },
      //打开链接下载apk版本
      handleDownload(file) {
        window.open(file)
      },
      //上传文件下载
      handleDownloadYL(file) {
        window.open(window._CONFIG['domianURL'] + '/sys/common/download/' + file)
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>